//
//  SLStarLevelViewController.m
//  StarLight
//
//  Created by 吴涛 on 16/6/9.
//  Copyright © 2016年 Duke.Wu. All rights reserved.
//

#import "SLStarLevelViewController.h"
#import "STPopup.h"
#import "SLCenterLabelTableViewCell.h"



@interface SLStarLevelViewController ()<UITableViewDelegate, UITableViewDataSource>

@property (nonatomic, strong) UITableView *tableview;

@property (nonatomic, strong) NSArray *levelArr;

@end

@implementation SLStarLevelViewController

- (instancetype)init{
  if (self = [super init]) {
    self.contentSizeInPopup = CGSizeMake(SCREEN_WIDTH-80, 200);
    self.landscapeContentSizeInPopup = CGSizeMake(400, 200);
    [STPopupNavigationBar appearance].barTintColor = [UIColor whiteColor];
    [STPopupNavigationBar appearance].tintColor = [UIColor whiteColor];
    [STPopupNavigationBar appearance].barStyle = UIBarStyleDefault;
    [STPopupNavigationBar appearance].titleTextAttributes = @{ NSForegroundColorAttributeName: SLYellowColor };
    self.title = @"会员等级";
  }
  return self;
}


- (void)viewDidLoad {
    [super viewDidLoad];
  [self.view addSubview:self.tableview];
  [self.tableview mas_makeConstraints:^(MASConstraintMaker *make) {
    make.edges.equalTo(self.view);
  }];
    // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


- (void)returnReturnStarLevel:(ReturnStarLevel)block{
  self.backBlock = block;
}

#pragma mark - Table view data source


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  
  return self.levelArr.count;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
  return 40;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  SLCenterLabelTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
  
  cell.centerLabel.text = self.levelArr[indexPath.row];
  
  return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
  self.backBlock(@(indexPath.row));
  [self dismissViewControllerAnimated:YES completion:nil];
}


- (NSArray *)levelArr{
  if (!_levelArr) {
    _levelArr = @[@"一星会员",@"二星会员",@"三星会员",@"四星会员",@"五星会员"];
  }
  return _levelArr;
}





- (UITableView *)tableview{
  if (!_tableview) {
    _tableview = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
    [_tableview registerClass:[SLCenterLabelTableViewCell class] forCellReuseIdentifier:@"cell"];
    _tableview.dataSource = self;
    _tableview.delegate = self;
  }
  return _tableview;
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
